//
//  ConditionSelectView.swift
//  MakeMoney
//
//  Created by Fan ZhiQiang on 2024/12/26.
//

import SwiftUI

struct ConditionSelectView: View {
    @Bindable var pathStore: PathStore
    @State private var param = NumberParam()
    
    var body: some View {
        Form {
            Section {
                DatePicker("请选择开始时间", selection: $param.startDate, in: dateRange(), displayedComponents: .date)
                    .environment(\.locale, Locale.init(identifier: "zh"))
                    //.environment(\.calendar, Calendar.init(identifier: .chinese))
                DatePicker("请选择结束时间", selection: $param.endDate, in: dateRange(), displayedComponents: .date)
                    .environment(\.locale, Locale.init(identifier: "zh"))
                    //.environment(\.calendar, Calendar.init(identifier: .chinese))
            }
            
            Section {
                ConditionNumberView(number: 1, conditionArea: .front, selectNumber: $param.front1)
                ConditionNumberView(number: 2, conditionArea: .front, selectNumber: $param.front2)
                ConditionNumberView(number: 3, conditionArea: .front, selectNumber: $param.front3)
                ConditionNumberView(number: 4, conditionArea: .front, selectNumber: $param.front4)
                ConditionNumberView(number: 5, conditionArea: .front, selectNumber: $param.front5)
            } header: {
                Text("前区号码")
            }
            
            Section {
                ConditionNumberView(number: 1, conditionArea: .hind, selectNumber: $param.hind1)
                ConditionNumberView(number: 2, conditionArea: .hind, selectNumber: $param.hind2)
            } header: {
                Text("后区号码")
            }
            
            Section {
                ConditionNumberView(number: 1, conditionArea: .ball, selectNumber: $param.ball)
            } header: {
                Text("摇奖球")
            }
            
            Section {
                HStack {
                    Button("折线图") {
                        pathStore.path.append(LineMarkPath())
                    }
                }
            } header: {
                Text("操作")
            }
            
        }
        .toolbar(.hidden, for: .tabBar)
        .navigationTitle("条件选择")
        .navigationDestination(for: ConditionResultPath.self) { _ in
            ConditionResultView(pathStore: pathStore, param: $param)
        }
        .navigationDestination(for: LineMarkPath.self) { _ in
            LineMarkView(pathStore: pathStore, param: $param)
        }
        .toolbar {
            ToolbarItem {
                Button("筛选") {
                    pathStore.path.append(ConditionResultPath())
                }
            }
        }
    }
}

#Preview {
    ConditionSelectView(pathStore: .init())
}

class ConditionSelectPath: PathName { }

struct NumberParam {
    var front1 = 0
    var front2 = 0
    var front3 = 0
    var front4 = 0
    var front5 = 0
    var hind1 = 0
    var hind2 = 0
    var ball = 0
    var startDate = lotteryStartDate
    var endDate = Date()
}
